package cn.lin.service.impl;

import cn.lin.domain.Classroom;
import cn.lin.mapper.ClassRoomMapper;
import cn.lin.service.ClassRoomServiceYH;
import cn.lin.vo.ClassRoomResourceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ClassRoomServiceYHImpl implements ClassRoomServiceYH {
    @Autowired
    private ClassRoomMapper classRoomMapper;
    @Override
    public List<Classroom> findClass(int classId) {
        System.out.println("jgioji");
        return classRoomMapper.findClass(classId);
    }

    /* zxy 课程资源目录查询 */
    @Override
    public Map<Integer,List<ClassRoomResourceVo>> findClassResource(List<Integer> catalogIdList) {

        List<ClassRoomResourceVo> classResource = classRoomMapper.findClassResource(catalogIdList);

        Set<Integer> catalogIdSet = new HashSet<>();
        for (ClassRoomResourceVo classRoomResourceVo : classResource) {
            Integer catalogId = classRoomResourceVo.getCatalogId();
            catalogIdSet.add(catalogId) ;
        }

        Map<Integer,List<ClassRoomResourceVo>> map = new HashMap<>() ;
        // 通过迭代器遍历目录id
        Iterator<Integer> iterator = catalogIdList.iterator();
        while (iterator.hasNext()){
            Integer catalogId = iterator.next();
            List<ClassRoomResourceVo> photoUrlList = new ArrayList<>();
            for (ClassRoomResourceVo classRoomResourceVo : classResource) {
                if (catalogId.equals(classRoomResourceVo.getCatalogId())){
                    photoUrlList.add(classRoomResourceVo);
                }
            }
            map.put(catalogId,photoUrlList);
        }
        return map;
    }

    // 根据班级id查询文件id
    @Override
    public List<Integer> getFileId(Integer classroomId) {
        return classRoomMapper.getFileId(classroomId) ;
    }
}
